/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MVC;

import common.*;
import java.io.File;
import java.net.InetAddress;
import java.util.HashMap;

/**
 * ModelMessOut
 * The Model of the MVC pattern
 * for the different sent types of message
 * @author Duy Duc, Metangmo
 */
public class ModelMessOut extends java.util.Observable{
    private Message nouveauMess;
    private File nouveauFile;
    private InetAddress addrDest;
    private int phase=0;
    
    /**
     * Constructor
     */
    
    public ModelMessOut() {
        
    }
    
    /**
     * addNouveauMessOut:
     * function adds the new sent message in the table of (IP Address-message) with his recipient's IP Address
     * and notifies the Observer(ChatNI) of the change 
     * @param mess
     *        New sent message
     * @param addrDest 
     *        IP Address of the message
     */
    
    public void addNouveauMessOut(Message mess,InetAddress addrDest){
        //Phase 0: The receipt's IP Address is sent to UDPcom
        if (phase==0){
            this.addrDest = addrDest;          
            setChanged();
            notifyObservers(addrDest);
            phase=1;
        }
        //Phase 1: The message is sent to UDPcom
        else{
            this.nouveauMess = mess;
            setChanged();
            notifyObservers(nouveauMess);
            phase=0;
        }
      
    }
    
    /**
     * addNouveauFileOut:
     * function adds the new sent file in the table of (IP Address-file) with his recipient's IP Address
     * and notifies the Observer(ChatNI) of the change 
     * @param file
     *        New sent file
     * @param addrDest 
     *        IP Address of the file
     */
    
    public void addNouveauFileOut(File file,InetAddress addrDest){
        //Phase 0: The receipt's IP Address is sent to TCPcom
        if (phase==0){
            this.addrDest = addrDest;
            setChanged();
            notifyObservers(addrDest);
            phase=1;
        }
        //Phase 1: The file is sent to TCPcom
        else{
            this.nouveauFile = file;
            setChanged();
            notifyObservers(nouveauFile);
            phase=0;
        }
      
    }
    
    /**
     * getNouveauMessOut:
     * function collects the table of new sent messages
     * @return 
     *        New sent message
     */

    public Message getNouveauMessOut() {
        return nouveauMess;
    }
    
    /**
     * getNouveauFileOut:
     * function collects the table of new sent files
     * @return 
     *        New sent file
     */

    public File getNouveauFileOut() {
        return nouveauFile;
    }
    
    /**
     * getAddrDest
     * function collects the IP Address of the recipient
     * @return
     *        IP Address of the recipient
     */

    public InetAddress getAddrDest() {
        return this.addrDest;
    }
    
    
    

}